home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
dev
/
e
/
audio_in_e.lha
/
audio_in_e
/
playahi.e
next >
Wrap
Text File
|
1999-01-08
|
4KB
|
131 lines
/************************************************************************
* *
* playahi.e 08.01.1999 by Rainer Müller *
* *
* an example how to use AHI with the Amiga E Language *
* *
* close the window to stop replaying *
* *
* compile: ec playahi *
* *
* use: playahi name name = name of the file you want to replay *
* *
************************************************************************/
OPT PREPROCESS
MODULE 'devices/ahi',
'dos/dos',
'exec/io', 'exec/memory', 'exec/nodes', 'exec/ports',
'intuition/intuition',
'utility/tagitem'
ENUM ER_NONE, ER_NOOPEN, ER_NOMEM, ER_NOLOAD, ER_NOPORT, ER_NOIOREQ, ER_NODEVICE, ER_NOWINDOW, ER_KICK
PROC main() HANDLE
DEF file=NIL
DEF ptr=NIL:PTR TO CHAR
DEF len=NIL
IF KickVersion(37)=FALSE THEN Raise(ER_KICK)
IF arg[]<>0
IF (file:=Open (arg, MODE_OLDFILE) ) =NIL THEN Raise(ER_NOOPEN)
len :=FileLength(arg)
IF (ptr :=AllocVec (len, MEMF_ANY+MEMF_PUBLIC)) =NIL THEN Raise(ER_NOMEM)
IF Read (file, ptr, len) <>len THEN Raise(ER_NOLOAD)
playahi(ptr,len)
ENDIF
EXCEPT DO
IF ptr THEN FreeVec(ptr)
IF file THEN Close (file)
SELECT exception
CASE ER_KICK; PrintF('need Kick 37+\n')
CASE ER_NOOPEN; PrintF('couldn`t open file\n')
CASE ER_NOMEM; PrintF('no memory\n')
CASE ER_NOLOAD; PrintF('problems while reading\n')
CASE ER_NONE; PrintF('all OK\n')
ENDSELECT
ENDPROC
PROC playahi(ptr,len) HANDLE
DEF ahidevice=-1
DEF ahiMP=NIL:PTR TO mp
DEF ahiIO=NIL:PTR TO ahirequest
DEF win =NIL:PTR TO window
DEF signals
DEF type
DEF frequency
DEF pri
DEF volume
type:=AHIST_M8S -> see ahi documentation for more types
frequency:=8000 -> frequency you want to replay with
pri:=128 -> priority you want to allocate the audio channel
volume:=$10000 -> the volume you want replay with, stored as a LONG fixed value, see ahi-doc formore information
IF (ahiMP:=CreateMsgPort() )=NIL THEN Raise(ER_NOPORT) -> create a message port
IF (ahiIO:=CreateIORequest(ahiMP, SIZEOF ahirequest))=NIL THEN Raise(ER_NOIOREQ) -> create a io-request
ahiIO.version:=4 -> see ahi-doc for more information
IF (ahidevice:=OpenDevice(AHINAME, AHI_DEFAULT_UNIT, ahiIO, 0)) THEN Raise(ER_NODEVICE) -> open audio-device
IF (win:=OpenWindowTagList(NIL, -> create a just-for-fun window
[WA_LEFT, 11,
WA_TOP, 11,
WA_INNERWIDTH, 80,
WA_INNERHEIGHT, 20,
WA_IDCMP, IDCMP_CLOSEWINDOW,
WA_FLAGS, WFLG_SMART_REFRESH OR WFLG_ACTIVATE OR WFLG_DRAGBAR OR
WFLG_NOCAREREFRESH OR WFLG_RMBTRAP OR WFLG_CLOSEGADGET,
WA_AUTOADJUST, 1, TAG_DONE]))=NIL THEN Raise(ER_NOWINDOW)
ahiIO.iostd.mn.ln.pri:=pri -> fill in the ahi-structures and then replay
ahiIO.iostd.command :=CMD_WRITE
ahiIO.iostd.data :=ptr -> pointer to the sampledata
ahiIO.iostd.length :=len -> number of bytes to replay
ahiIO.iostd.offset :=0
ahiIO.type :=type
ahiIO.frequency :=frequency
ahiIO.volume :=volume
ahiIO.position :=$08000 -> Centered, see ahi-doc
ahiIO.link :=NIL
SendIO(ahiIO) -> start replay
/* wait till replaying is finished, or you stop replaying by closing the window */
signals:=Wait( Shl(1, win.userport.sigbit) OR Shl(1, ahiMP.sigbit) )
IF (signals AND Shl(1, win.userport.sigbit))
WriteF('break by user\n')
AbortIO(ahiIO)
WaitIO(ahiIO)
ENDIF
IF (signals AND Shl(1, ahiMP.sigbit))
WriteF('break by ahi\n')
ENDIF
EXCEPT DO
IF win THEN CloseWindow (win)
IF ahidevice=0 THEN CloseDevice (ahiIO)
IF ahiIO THEN DeleteIORequest(ahiIO)
IF ahiMP THEN DeleteMsgPort (ahiMP)
SELECT exception
CASE ER_NOPORT; PrintF('couldn`t create port\n')
CASE ER_NOIOREQ; PrintF('couldn`t create iorequest\n')
CASE ER_NODEVICE; PrintF('couldn`t open ahi-device V4+\n')
CASE ER_NOWINDOW; PrintF('couldn`t open window\n')
ENDSELECT
ENDPROC